<?php include_partial('common/flashes') ?>
<form id="doctor-answer-form" action="<?php echo url_for('/doctor-answer/' . $form->getObject()->getId()) ?>" method="post">
    <?php echo $form->renderHiddenFields(false) ?>
    <div class="imperative">Please kindly provide an answer to this question!</div>
    <div class="row">
        <div><?php echo $form->getObject()->getTopic() ?></div>
    </div>
    <?php include_partial("common/input_field", array("form" => $form, "field" => "answer")) ?>
    <div class="row">
        <ul>
            <li>
                <button id="submit-doctor-answer" type="submit" class="blue-button-30">Submit</button>
                <input id="done-doctor-answer" type="button" value="Done" class="brown-button-30">
            </li>
        </ul>
    </div>
    <div class="clear"></div>
</form>
<script type="text/javascript">
    //<![CDATA[
    $(document).ready(function(){
        // make an attempt to submit this form
        $('#submit-doctor-answer').click(function() {
            $('#doctor-answer-form').ajaxSubmit(function(data){                 
                if(hasForm(data))
                {         
                    $('#answer-form').html(data);
                }
                else{                 
                    // automatically load the doctor question and answer form so we've a fresh form without any flash messages associated with it
                    $("#answer-form").load('/doctor-answer/<?php echo $form->getObject()->getId() ?>');
                }
            });
            return false;
        });
        
        $("#done-doctor-answer").click(function(){
            $('#doctor-questions-and-answers').load('/doctor-answer-done/<?php echo $form->getObject()->getDoctorId() ?>');
            $.fn.colorbox.close();
        }); 
    });
    //]]>
</script>